package com.zhong.common.core.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IgnoreUpdate;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsKey;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.zhong.common.annotation.QueryField;
import com.zhong.common.core.enums.QueryCondition;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * Entity基类
 *
 * @author zhongzc
 */
@Data
public class BaseEntity implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 用户ID */
    @IsKey
    @TableId(type = IdType.ASSIGN_UUID)
    @Column(length = 56)
    private String id;

    /** 创建者 */
    @Column(comment = "创建者")
    @QueryField(condition = QueryCondition.like)
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    /** 创建时间 */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(comment = "创建时间",type = MySqlTypeConstant.DATETIME)
    private Date createTime;

    /** 更新者 */
    @Column(comment = "更新者")
    @TableField(fill = FieldFill.UPDATE)
    private String updateBy;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.UPDATE)
    @Column(comment = "更新时间",type = MySqlTypeConstant.DATETIME)
    private Date updateTime;

//    /** 备注 */
//    @Column(comment = "备注",type = MySqlTypeConstant.TEXT)
//    private String remark;

    @IgnoreUpdate
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @QueryField(condition = QueryCondition.ge,fieldName = "createTime")
    private Date beginCreateTime;

    @IgnoreUpdate
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @QueryField(condition = QueryCondition.le,fieldName = "createTime")
    private Date endCreateTime;

    @IgnoreUpdate
    @TableField(exist = false)
    private Page page;

    @JsonIgnore
    public Page getPage() {
        if (page == null) {
            page = new Page();
        }
        return page;
    }
}
